winsafe\ole\com_interfaces/
ipersistfile.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::ole::{privs::*, vts::*};
6use crate::prelude::*;
7
8com_interface! { IPersistFile: "0000010b-0000-0000-c000-000000000046";
9	/// [`IPersistFile`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-ipersistfile)
10	/// COM interface.
11	///
12	/// Automatically calls
13	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
14	/// when the object goes out of scope.
15}
16
17impl ole_IPersist for IPersistFile {}
18impl ole_IPersistFile for IPersistFile {}
19
20/// This trait is enabled with the `ole` feature, and provides methods for
21/// [`IPersistFile`](crate::IPersistFile).
22///
23/// Prefer importing this trait through the prelude:
24///
25/// ```no_run
26/// use winsafe::prelude::*;
27/// ```
28pub trait ole_IPersistFile: ole_IUnknown {
29	/// [`IPersistFile::GetCurFile`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-ipersistfile-getcurfile)
30	/// method.
31	#[must_use]
32	fn GetCurFile(&self) -> HrResult<String> {
33		let mut pstr = std::ptr::null_mut::<u16>();
34		ok_to_hrresult(unsafe { (vt::<IPersistFileVT>(self).GetCurFile)(self.ptr(), &mut pstr) })
35			.map(|_| htaskmem_ptr_to_str(pstr))
36	}
37
38	/// [`IPersistFile::IsDirty`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-ipersistfile-isdirty)
39	/// method.
40	#[must_use]
41	fn IsDirty(&self) -> HrResult<bool> {
42		okfalse_to_hrresult(unsafe { (vt::<IPersistFileVT>(self).IsDirty)(self.ptr()) })
43	}
44
45	/// [`IPersistFile::Load`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-ipersistfile-load)
46	/// method.
47	fn Load(&self, file_name: &str, dw_mode: co::STGM) -> HrResult<()> {
48		ok_to_hrresult(unsafe {
49			(vt::<IPersistFileVT>(self).Load)(
50				self.ptr(),
51				WString::from_str(file_name).as_ptr(),
52				dw_mode.raw(),
53			)
54		})
55	}
56
57	/// [`IPersistFile::Save`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-ipersistfile-save)
58	/// method.
59	fn Save(&self, file_name: Option<&str>, remember: bool) -> HrResult<()> {
60		ok_to_hrresult(unsafe {
61			(vt::<IPersistFileVT>(self).Save)(
62				self.ptr(),
63				WString::from_opt_str(file_name).as_ptr(),
64				remember as _,
65			)
66		})
67	}
68
69	/// [`IPersistFile::SaveCompleted`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-ipersistfile-savecompleted)
70	/// method.
71	fn SaveCompleted(&self, file_name: &str) -> HrResult<()> {
72		ok_to_hrresult(unsafe {
73			(vt::<IPersistFileVT>(self).SaveCompleted)(
74				self.ptr(),
75				WString::from_str(file_name).as_ptr(),
76			)
77		})
78	}
79}